package org.baicaixiaozhan.springbootwebdemo1.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;

import java.io.Serializable;

/**
 * DESC: 返回给前端的通用模板类
 *
 * @author : baicaixiaozhan
 * @since : 2021-01-30
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResultTemplate<T> implements Serializable {
    private Integer statusCode;
    private String statusDesc;
    private T massage;

    public static <T> ResultTemplate<T> success() {
        return new ResultTemplate<T>(HttpStatus.OK.value(),
                HttpStatus.OK.name(),
                null);
    }

    public static <T> ResultTemplate<T> success(T massage) {
        return new ResultTemplate<T>(HttpStatus.OK.value(),
                HttpStatus.OK.name(),
                massage);
    }

    public static <T> ResultTemplate<T> error() {
        return new ResultTemplate<T>(HttpStatus.BAD_REQUEST.value(),
                HttpStatus.BAD_REQUEST.name(),
                null);
    }

    public static <T> ResultTemplate<T> error(HttpStatus httpStatus, T massage) {
        return new ResultTemplate<T>(httpStatus.value(),
                httpStatus.name(),
                massage);
    }
}
